#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x

trigger-domains-post-app-rename-setup() {
  declare desc="updates VHOST and URLS files during rename"
  declare trigger="post-app-rename-setup"
  declare OLD_APP="$1" NEW_APP="$2"

  if [[ -f "$DOKKU_ROOT/$NEW_APP/URLS" ]]; then
    sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/URLS"
  fi
  if [[ -f "$DOKKU_ROOT/$NEW_APP/VHOST" ]]; then
    sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/VHOST"
  fi
}

trigger-domains-post-app-rename-setup "$@"
